package com.example.day12;

import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private Toolbar mToolbar;
    private ViewPager mViewpager;
    private TabLayout mTablayout;
    private LinearLayout mContent;
    private NavigationView mNavigationview;
    private DrawerLayout mDrawerlayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mViewpager = (ViewPager) findViewById(R.id.viewpager);
        mTablayout = (TabLayout) findViewById(R.id.tablayout);
        mContent = (LinearLayout) findViewById(R.id.content);
        mNavigationview = (NavigationView) findViewById(R.id.navigationview);
        mDrawerlayout = (DrawerLayout) findViewById(R.id.drawerlayout);


        // toolbar
        mToolbar.setTitle("");
        setSupportActionBar(mToolbar);


        // 关联toolbar和侧滑区域

        ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerlayout, mToolbar, R.string.open, R.string.close);
        mDrawerlayout.addDrawerListener(actionBarDrawerToggle);
        actionBarDrawerToggle.syncState();

        // 解决侧滑选项图片为灰色问题
        mNavigationview.setItemIconTintList(null);

        //viewpager  fragment 结合

        List<Fragment> fragmentList = new ArrayList<>();
        HomeFragment homeFragment = new HomeFragment();
        ProjectFragment projectFragment = new ProjectFragment();

        fragmentList.add(homeFragment);
        fragmentList.add(projectFragment);

        HomeViewpagerAdapter homeViewpagerAdapter = new HomeViewpagerAdapter(getSupportFragmentManager(), fragmentList);
        mViewpager.setAdapter(homeViewpagerAdapter);

        // viewpager tablayout 结合

        mTablayout.setupWithViewPager(mViewpager);

        mTablayout.getTabAt(0).setText("首页").setIcon(R.drawable.ease_chat_takepic_normal);
        mTablayout.getTabAt(1).setText("项目").setIcon(R.drawable.ease_chat_takepic_normal);

    }
}
